const getPrizeDescList = () => {
	return new Promise((resolve, reject) => {
		uniCloud.callFunction({
			name: 'prizeDesc',
			data: {
				action: 'getPrizeDescList'
			},
			success: (res) => {
				if (res.result.code === 200) {
					resolve(res.result.data);
				} else {
					reject(res.result.message || '获取奖品描述列表失败');
				}
			},
			fail: (err) => {
				reject('网络请求失败: ' + err.errMsg);
			}
		});
	});
};

const addPrizeDesc = (data) => {
	return new Promise((resolve, reject) => {
		uniCloud.callFunction({
			name: 'prizeDesc',
			data: {
				action: 'addPrizeDesc',
				...data
			},
			success: (res) => {
				if (res.result.code === 200) {
					resolve({
						id: res.result.id,
						message: res.result.message
					});
				} else {
					reject(res.result.message || '添加奖品描述失败');
				}
			},
			fail: (err) => {
				reject('网络请求失败: ' + err.errMsg);
			}
		});
	});
};

const updatePrizeDesc = (id, data) => {
	return new Promise((resolve, reject) => {
		uniCloud.callFunction({
			name: 'prizeDesc',
			data: {
				action: 'updatePrizeDesc',
				_id: id,
				...data
			},
			success: (res) => {
				if (res.result.code === 200) {
					resolve({
						updated: res.result.updated,
						message: res.result.message
					});
				} else {
					reject(res.result.message || '更新奖品描述失败');
				}
			},
			fail: (err) => {
				reject('网络请求失败: ' + err.errMsg);
			}
		});
	});
};

const deletePrizeDesc = (id) => {
	return new Promise((resolve, reject) => {
		uniCloud.callFunction({
			name: 'prizeDesc',
			data: {
				action: 'deletePrizeDesc',
				_id: id
			},
			success: (res) => {
				if (res.result.code === 200) {
					resolve({
						deleted: res.result.deleted,
						message: res.result.message
					});
				} else {
					reject(res.result.message || '删除奖品描述失败');
				}
			},
			fail: (err) => {
				reject('网络请求失败: ' + err.errMsg);
			}
		});
	});
};

export {
	getPrizeDescList,
	addPrizeDesc,
	updatePrizeDesc,
	deletePrizeDesc
};